package com.sinothk.software.utils;

import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;
import com.sinothk.software.ResourceTable;

public class ToastUtil {
    Context mContext;

    public ToastUtil(Context context) {
        mContext = context;
    }

    public void show(String msg) {

        DirectionalLayout toastLayout = (DirectionalLayout) LayoutScatter.getInstance(mContext)
                .parse(ResourceTable.Layout_layout_toast, null, false);

        Text msg_toast = (Text) toastLayout.findComponentById(ResourceTable.Id_msg_toast);
        msg_toast.setText(msg);

        new ToastDialog(mContext)
                .setContentCustomComponent(toastLayout)
                .setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT)
                .setOffset(0, 600)
                .setAlignment(LayoutAlignment.CENTER)
                .show();
    }
}
